package cn.tedu.eguser.controller;

import cn.tedu.eguser.mapper.UserMapper;
import cn.tedu.eguser.pojo.dto.UserAddParam;
import cn.tedu.eguser.pojo.entity.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/v1/user/")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @PostMapping("add")
    public String add(UserAddParam userAddParam){
        System.out.println(userAddParam);
        User user = new User();
        BeanUtils.copyProperties(userAddParam,user);
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        int result = userMapper.addUser(user);
        if (result > 0){
            return "用户添加成功！";
        }
        return "用户添加失败！用户不存在";

    }


}
